package cn.zwk.domain.system.model.query;

import cn.zwk.common.model.BasePageQuery;
import cn.zwk.repository.po.Role;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;

import java.time.LocalDateTime;

/**
 * 角色分页查询对象
 *
 * @author Ray
 * @since 2022/6/3
 */
@Getter
@Setter
public class RolePageQuery extends BasePageQuery {

    /**
     * 角色名称
     */
    private String name;
    /**
     * 角色编码
     */
    private String code;

    @JsonFormat(pattern = "yyyy-MM-dd")
    private LocalDateTime startDate;

    @JsonFormat(pattern = "yyyy-MM-dd")
    private LocalDateTime endDate;

    public final LambdaQueryWrapper<Role> buildQuery() {
        LambdaQueryWrapper<Role> queryWrapper = new LambdaQueryWrapper<>();
        if (name != null) {
            queryWrapper.like(Role::getName, name);
        }
        if (code != null) {
            queryWrapper.like(Role::getCode, code);
        }
        if (startDate!= null) {
            queryWrapper.ge(Role::getCreateTime,startDate);
        }
        if (endDate != null) {
            queryWrapper.le(Role::getCreateTime, endDate);
        }
        return queryWrapper;
    }
}
